package com.logansoft.zhxypkoa.components;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.springframework.stereotype.Component;

@Component
public class UrlTool {

	public boolean match(String path) {
		if (path.startsWith("/api/browser") || path.equals("/login") || path.equals("/api/menus/search/getMyMenus") || path.equals("/api/menus/search/getMyTopMenus")) {
			return true;
		}
		return false;
	}

	public String findResource(String path) {
		String pattern = "^/api/(\\w+)";
		Pattern p = Pattern.compile(pattern);
		Matcher m = p.matcher(path);
		if (m.find()) {
			return m.group(1);
		}
		return null;
	}

	public String findCtrl(String path) {
		String pattern = "^/search/(\\w+)";
		Pattern p = Pattern.compile(pattern);
		Matcher m = p.matcher(path);
		if (m.find()) {
			return m.group(1);
		}
		return null;
	}

}
